package com.chixing.server.listener;

import com.alibaba.fastjson.JSON;
import com.chixing.pojo.RequestMessage;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Objects;

@Component
@RabbitListener(queues = "RemindToReturnTheCar")
public class Receiver {


    @Autowired
    private SimpMessagingTemplate messagingTemplate;


    @RabbitHandler
    public void process(String context){
        System.out.println("Receiver : " + context);

        RequestMessage mqTask =  JSON.parseObject(context,RequestMessage.class) ;
        if (Objects.equals( mqTask.getType(), "2" )) {
            String destination = "/topic/" +mqTask.getRoom();
            messagingTemplate.convertAndSend( destination, mqTask);
        }
    }
}